标签打印机TSPL打印指令

您所在的位置:网站首页 tsc me240恢复出厂 标签打印机TSPL打印指令

标签打印机TSPL打印指令

2023-09-17 22:35| 来源: 网络整理| 查看: 265

ESC TSPL指令

tspl是一套通用的标签打印指令,许多主流标签打印机都支持此指令。但是网上资料较少,这里主要分享一下android和ios的打印基本算法。

指令文档

指令文档网上较少,这里引用一个链接吧 TSC条码打印机指令TSPL手册,各个厂商可能基于此指令有少量diy,具体可以查看自己打印机对应厂商的文档。

打印

请详细阅读指令手册,具体打印步骤,以打印图片为例:

SIZE 设置标签大小GAP 设置标签缝大小BITMAP 绘制图像PRINT 打印

如果需要反向打印,需要在PRINT前调用DIRCTION。 注意:每条指令后需要添加 "\r\n"

android示例代码 ///写入指令 public boolean tspl_writeCmd(String cmd, boolean end) { if (TextUtils.isEmpty(cmd)) { return false; } cmd = end ? (cmd + "\r\n") : cmd; JXLog.d(TAG, "tspl_writeCmd: " + cmd); byte[] data; try { data = cmd.getBytes(); } catch (Exception var4) { JXLog.e(TAG, "String getBytes('GBK') failed"); return false; } return mAPI.isConnected() && mAPI.flushReadBuffer() && mAPI.writeBuffer(data, 0, data.length); } ///设置纸张和gap public boolean tspl_pageSetup(int widthInMM, int heightInMM, int gapInMM) { if (widthInMM int bmp_size_x = bmp.getWidth(); int bmp_size_y = bmp.getHeight(); int byteWidth = (bmp_size_x - 1) / 8 + 1; //8个点一个byte,所以要先计算byteWidth int byteHeight = bmp_size_y; if (byteWidth endY = bmp_size_y; } else { endY = startY + unitHeight; } int byteLen = (endY - startY) * byteWidth;//每个包数据的字节个数 dataByte = new byte[byteLen]; for (int y = startY; y color = bmp.getPixel(x, y); A = color >> 24 & 0xFF; R = color >> 16 & 0xFF; G = color >> 8 & 0xFF; B = color & 0xFF; //经验公式二值化,透明视为白色 if (A == 0 || R * 0.3 + G * 0.59 + B * 0.11 > 127) { dataByte[(y - startY) * byteWidth + x / 8] |= (0x80 >> (x % 8)); } } } int curUnitHeight = n == unitCount - 1 ? (byteHeight - (n * unitHeight)) : unitHeight; String cmdHeader = "BITMAP " + start_x + "," + (start_y + startY) + "," + byteWidth + "," + curUnitHeight + "," + 0 + ","; boolean success = tspl_writeCmd(cmdHeader, false) && mAPI.writeBuffer(dataByte, 0, dataByte.length); if (success) { mAPI.writeBuffer(new byte[]{0x0D, 0x0A}, 0, 2); } else { return false; } } return true; } /// 打印 public boolean tspl_print(int count, boolean isReverse) { if (count 65535) count = 65535; String cmd = String.format("PRINT %d,1", count); return tspl_direction(isReverse) && tspl_writeCmd(cmd, true); }

ios代码就不贴了,算法基本一致。如果恰好需要,希望对你有帮助!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3